package com.zzyl;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONUtil;
import com.zzyl.dto.LoginDto;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpLogging;

import java.util.HashMap;
import java.util.Map;

class test {

    @Test
    public void Test() {
        //最简单的HTTP请求，可以自动通过header等信息判断编码，不区分HTTP和HTTPS
        String result = HttpUtil.get("http://localhost:9995/rsecurity/login");
        System.out.println(result);
    }

    ////可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中
    @Test
    public void TestGet() {
        String url = "http://Localhost:9995/nursing_project";
        HttpRequest request = HttpUtil.createRequest(Method.GET, url);
        Map<String, Object> params = new HashMap<>();
        params.put("pageNum", 1);
        params.put("pageSize", 5);
        params.put("name", "测试");

        HttpResponse request1 = request.form(params).execute();
        String body = request1.body();
        System.out.println(body);


    }

    @Test
    public void TestPost() {
        LoginDto dto =new LoginDto();
        dto.setUsername("admin@qq.com");
        dto.setPassword("123456");
        String json = JSONUtil.toJsonStr(dto);
        String post = HttpUtil.post("http://localhost:9995/security/login", json);
        System.out.println(post);
    }
}